import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:member_center_sdk_example/components/count_button.dart';
import 'package:member_center_sdk_example/components/loading_button.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    SmsLoginState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    child: Column(
      children: <Widget>[
        Container(
          child: TextField(
            controller: state.userNameController,
            keyboardType: TextInputType.number,
            inputFormatters: <TextInputFormatter>[
              WhitelistingTextInputFormatter.digitsOnly
            ],
            decoration: InputDecoration(
                icon: Icon(Icons.account_box), labelText: "手机号码"),
          ),
          padding: EdgeInsets.all(30),
        ),
        Divider(
          height: 0.2,
        ),
        Container(
          child: Row(
            children: <Widget>[
              Expanded(
                child: TextField(
                  controller: state.codeController,
                  keyboardType: TextInputType.number,
                  inputFormatters: <TextInputFormatter>[
                    WhitelistingTextInputFormatter.digitsOnly
                  ],
                  decoration:
                      InputDecoration(icon: Icon(Icons.sms), labelText: "验证码"),
                ),
              ),
              CountButton("发送", state.remainSeconds, () {
                dispatch(SmsLoginActionCreator.onSendSms());
              }),
            ],
          ),
          padding: EdgeInsets.all(30),
        ),
        new Container(
          child: LoadingButton("立即登录", state.isLoading, () {
            dispatch(SmsLoginActionCreator.onLoginAction());
          }),
        ),
        new Container(
          padding: EdgeInsets.all(25),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              GestureDetector(
                onTap: () {
                  dispatch(SmsLoginActionCreator.onSwitchAction());
                },
                child: Text(
                  "密码登录",
                  style: TextStyle(
                      fontSize: 16, decoration: TextDecoration.underline),
                ),
              ),
              new Container(),
              GestureDetector(
                onTap: () {
                  //dispatch(SmsLoginActionCreator.onRegisterAction());
                },
                child: Text(
                  "注 册",
                  style: TextStyle(
                      fontSize: 16, decoration: TextDecoration.underline),
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}
